package com.itany.corejava.code08_常用类.string类;

import java.util.Arrays;

/**
 * @author 石小俊
 * 2024年07月19日 13:34
 */
public class Test02_练习 {

    public static void main(String[] args) {
        String s = " Hello World ";
        System.out.println("字符串长度:" + s.length());
        // 去除首尾的空格
        s = s.trim();
        System.out.println("字符串长度:" + s.length());
        System.out.println("字符o第一次出现的索引位置:" + s.indexOf("o"));
        System.out.println("字符l最后一次出现的索引位置:" + s.lastIndexOf("l"));
        String s2 = "admin jack tom admin tom admin jack admin";
        // 如果是一个字符串,以第一个字符的索引位置为准
        System.out.println("admin字符串第一次出现的索引位置:" + s2.indexOf("admin"));
        System.out.println("admin字符串在索引3之后第一次出现的索引位置:" + s2.indexOf("admin", 3));
        System.out.println("admin字符串从起始位置到索引为24之前最后一次出现的索引位置:" + s2.lastIndexOf("admin", 24));
        System.out.println("admin字符串从起始位置到索引为35之前最后一次出现的索引位置:" + s2.lastIndexOf("admin", 35));

        System.out.println(s.substring(6));
        System.out.println(s.substring(4, 7));
        System.out.println(s.concat(",I am admin"));
        System.out.println("字符串s是否为空:" + s.isEmpty());
        String s3 = new String();
        System.out.println("字符串s3是否为空:" + s3.isEmpty());

        System.out.println("获取字符串s索引为4的字符:" + s.charAt(4));
        System.out.println("字符串s2是否以admin开头:" + s2.startsWith("admin"));
        System.out.println("字符串s2是否以admin结尾:" + s2.endsWith("admin"));
        System.out.println("字符串s中是否包含Hello:" + s.contains("Hello"));

        String s4 = "hello world";
        System.out.println(s.equals(s4));
        System.out.println(s.equalsIgnoreCase(s4));

        System.out.println("大写:" + s.toUpperCase());
        System.out.println("小写:" + s.toLowerCase());
        System.out.println(s2.replace(" ", "-"));
        String[] arr = s2.split(" ");
        System.out.println(Arrays.toString(arr));

        String s5 = String.join("-", "Hello", "World", "I", "am", "admin");
        System.out.println(s5);
        String[] arr2 = new String[]{"Hello", "World", "I", "am", "admin"};
        String s6 = String.join(", ", arr2);
        System.out.println(s6);
        System.out.println(Arrays.toString(arr2));
    }

}
